package conf2.ui;

import conf2.model.EActor.Side;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ActorInfoGlassPane extends JPanel
{

    private static JFrame hackFrame = new JFrame();
    private static final Color BG_COLOR = new Color(0, 0, 0, 64);
    private static final Color SHADOW_COLOR = new Color(0, 0, 0, 127);
    private final JPanel shadow;
    private final JPanel actorPanel;

    private ActorInfoGlassPane(
            final JFrame parent,
            final String name,
            final String desc,
            final int atkVal,
            final Image img,
            final Side side)
    {
        setSize(parent.getContentPane().getSize());
        actorPanel = new ActorInfoPanel(name, desc, atkVal, img, side);

        // I use a frame and its pack() method to give the panel its proper size,
        // since I don't know any better.
        hackFrame.setContentPane(actorPanel);
        hackFrame.pack();

        setLayout(null);
        setOpaque(false);
        setBackground(new Color(0, 0, 0, 64));

        // TODO: Get rid of hardcoded values.

        shadow = new JPanel();
        shadow.setSize(actorPanel.getSize());
        shadow.setBackground(SHADOW_COLOR);

        add(shadow);
        add(actorPanel, 0);

        addMouseListener(new MouseAdapter()
        {

            @Override
            public void mousePressed(MouseEvent e)
            {
                setVisible(false);
            }
        });

    }

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(BG_COLOR);
        g.fillRect(0, 0, getWidth(), getHeight());

        // Setting the locations here instead of in the constructor
        // helped with a strange bug.
        actorPanel.setLocation(300 - actorPanel.getWidth() / 2, 300 - actorPanel.getHeight() / 2);
        shadow.setLocation(actorPanel.getX() + 3, actorPanel.getY() + 3);
    }

    public static void show(
            final JFrame parent,
            final String name,
            final String desc,
            final int atkVal,
            final Image img,
            final Side side)
    {
        final ActorInfoGlassPane pane = new ActorInfoGlassPane(parent, name, desc, atkVal, img, side);
        parent.setGlassPane(pane);

        pane.setVisible(true);
    }
}
